package com.vitaf.cash.app.ui.fragment

import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.vitaf.cash.app.R
import com.vitaf.cash.app.common.VitafComFmtV2
import com.vitaf.cash.app.configs.GombeCreditApiPath
import com.vitaf.cash.app.configs.GombeCreditApiUrl
import com.vitaf.cash.app.configs.GombeCreditApiUrl.addCommonParams
import com.vitaf.cash.app.configs.VitafConfigs
import com.vitaf.cash.app.databinding.VitafFmtStatusBinding
import com.vitaf.cash.app.event.VitafEventData
import com.vitaf.cash.app.event.VitafEventPointType
import com.vitaf.cash.app.request.IHttpCallback
import com.vitaf.cash.app.ui.activity.VitafUserAdviceTypeAct
import com.vitaf.cash.app.ui.activity.VitafUserLoginAct
import com.vitaf.cash.app.ui.adapter.VitafStatusDetailsWalletApt
import com.vitaf.cash.app.ui.dialog.VitafStatusDetailsWalletOnlyOneDlog
import com.vitaf.cash.app.ui.dialog.VitafUserDataDeleteDlog
import com.vitaf.cash.app.ui.dialog.VitafWalletAddDlog
import com.vitaf.cash.app.ui.dialog.VitafWalletBindOtherDlog
import com.vitaf.cash.app.ui.dialog.VitafWalletDeleteDlog
import com.vitaf.cash.app.utils.VitafDensityUtil
import com.vitaf.cash.app.utils.VitafTitleBarUtil
import com.vitaf.cash.app.utils.decoration.LinearSpacingItemDecoration
import com.vitaf.cash.app.utils.helper.VitafConfigsHp
import com.vitaf.cash.app.utils.helper.VitafProcessHp
import com.vitaf.cash.app.utils.helper.VitafScoreDialogHp
import com.vitaf.cash.app.utils.shared.VitafSharedHp
import com.vitaf.cash.lib.adapter.VitafOnSingleClickListener
import org.json.JSONObject
import java.math.BigDecimal

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/12/10 14:53
 * @Annotation：审核中、放款中、已拒绝
 */
class VitafStatusFmt : VitafComFmtV2() {
    private var _binding: VitafFmtStatusBinding? = null
    private val binding get() = _binding ?: throw IllegalStateException(
        "gombe credit status binding because it is null. Either the view hasn't been created yet, or it has already been destroyed."
    )
    private var deleteDataAfterDate = ""
    private var walletAdapter: VitafStatusDetailsWalletApt? = null

    //只有一个账户提示
    private var walletOnlyOneDialog: VitafStatusDetailsWalletOnlyOneDlog? = null

    public override var pageName: String = "Apply_Status_Page"

    override fun createVitafContentView(inflater: LayoutInflater): View? {
        _binding = VitafFmtStatusBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initializeVitafViews() {
        _binding?.statusTitleBarLayout?.setPadding(0, VitafTitleBarUtil.getStatusBarHeight() + VitafDensityUtil.dp2px(10f), 0, 0)
        _binding?.statusPageRefreshLayout?.setColorSchemeResources(R.color.theme, R.color.purple_500)

        initGombeCreditApplyDetailsWalletListView()
        _binding?.applyStatusLayout?.visibility = View.GONE
    }

    override fun setupVitafEventListeners() {
        _binding?.imgCustomer?.setOnClickListener(object : VitafOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                onClickCustomer(pageName)
            }
        })
        _binding?.statusPageRefreshLayout?.setOnRefreshListener {
            publishEventData(VitafEventData(VitafEventData.TYPE.GOMBECREDIT_PROCESS_REFRESH))
        }
        //refresh
        _binding?.btnRefreshStatus?.setOnClickListener(object : VitafOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                showVitafLoading()
                publishEventData(VitafEventData(VitafEventData.TYPE.GOMBECREDIT_PROCESS_REFRESH))
            }
        })

        //新增账户
        _binding?.btnWalletAdd?.setOnClickListener(object : VitafOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                showGombeCreditWalletAddDialog()
            }
        })
        //意见反馈
        _binding?.btnFeedback?.setOnClickListener(object : VitafOnSingleClickListener(){
            override fun onSingleClick(v: View?) {
                onIntent(VitafUserAdviceTypeAct::class.java)
            }
        })
        //删除用户数据
        _binding?.btnDeleteData?.setOnClickListener {
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_CLICK.USER_DATA_CLEAR,pageName)
            showGombeCreditClearDataDialog()
        }
    }

    override fun loadVitafData() {
//        GombeCreditLogger.e(">>>>>>>>>>>>>>initData>>>>>>>>>>>>>>")
//        loadGombeCreditApplyDetailsAction()
    }

    /**
     * 初始化Views
     */
    private fun initGombeCreditApplyDetailsWalletListView(){
        _binding?.walletListView?.isNestedScrollingEnabled = false
        binding.walletListView.isFocusableInTouchMode = false //不需要焦点
        val layoutManager = LinearLayoutManager(requireContext())
        layoutManager.orientation = RecyclerView.VERTICAL
        binding.walletListView.layoutManager = layoutManager
        val topDecoration = VitafDensityUtil.dp2px(12f)
        binding.walletListView.addItemDecoration(LinearSpacingItemDecoration(0, 0, topDecoration, topDecoration))
        walletAdapter = VitafStatusDetailsWalletApt(binding.walletListView)
        binding.walletListView.adapter = walletAdapter
        binding.walletListView.itemAnimator = DefaultItemAnimator()
        walletAdapter?.setOnItemChildClickListener { _, childView, position ->
            walletAdapter?.let {
                val item = it.getItem(position)
                if (childView.id == R.id.walletDelete){
                    showGombeCreditWalletDeleteDialog(item)
                }
            }
        }
    }

    /**
     * 设置贷款信息
     */
    private fun showGombeCreditApplyDetails(data: JSONObject){
        _binding?.applyStatusLayout?.visibility = View.VISIBLE

        _binding?.textLoanAmount?.text = BigDecimal(data.optString("amount")).stripTrailingZeros().toPlainString()
        _binding?.textLoanTerm?.text = String.format(getString(R.string.vitaf_status_loan_days),data.optString("days"))

        //审核中
        val isReviewing = VitafProcessHp.isGombeCreditReviewing()
        if (isReviewing){
            pageName = "Reviewing_Page"
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_PAGE.LOAN_REVIEWING_START)
            showGombeCreditApplyReviewingView()
            return
        }
        //放款中
        val isDisbursing = VitafProcessHp.isGombeCreditDisbursing()
        if (isDisbursing){
            pageName = "Disbursing_Page"
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_PAGE.LOAN_DISBURSING_START)
            showGomeCreditApplyDisbursingView()
            return
        }
        //已拒绝
        val isRejected = VitafProcessHp.isGombeCreditRejected()
        if (isRejected){
            pageName = "Rejected_Page"
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_PAGE.LOAN_REJECTED_START)
            showGomeCreditApplyRejectedView()
            return
        }

        //待还款
//        publishEventData(VitafEventData(VitafEventData.TYPE.GOMBECREDIT_SHOW_REPAY))
    }

    /**
     * 审核中
     */
    private fun showGombeCreditApplyReviewingView(){
        _binding?.imageStatusIcon?.setImageResource(R.mipmap.gombe_credit_image_status_reviewing_icon)

        val showKey = getString(R.string.vitaf_status_reviewing_2)
        val showText = String.format(getString(R.string.vitaf_status_reviewing_1),showKey)
        val startIndex = showText.indexOf(showKey)
        val spannable = SpannableString(showText)
        spannable.setSpan(ForegroundColorSpan(getColor(R.color.gombe_credit_FFEC273A)), startIndex, startIndex + showKey.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        //加粗
//        spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + showKey.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        _binding?.textStatusTips?.setTextColor(getColor(R.color.gombe_credit_FF191919))
        _binding?.textStatusTips?.text = spannable
        _binding?.textStatusTips2?.text = getString(R.string.vitaf_status_reviewing_3)
        _binding?.textStatus?.text = getString(R.string.vitaf_status_reviewing)
        _binding?.textStatus?.setTextColor(getColor(R.color.gombe_credit_FF2E86F6))
        _binding?.btnRefreshStatus?.visibility = View.VISIBLE
        _binding?.textStatusTips3?.text = getString(R.string.vitaf_status_reviewing_5)
        _binding?.textStatusTips3?.visibility = View.VISIBLE
        _binding?.walletListView?.visibility = View.VISIBLE
        _binding?.btnFeedback?.visibility = View.GONE
        _binding?.btnDeleteData?.visibility = View.GONE

        _binding?.btnWalletAdd?.visibility = View.GONE
        //法语区才显示添加收款账户按钮
        if (VitafConfigs.isGombeCreditFrench()){
            _binding?.btnWalletAdd?.visibility = View.VISIBLE
        }
        //加载收款账户列表
        loaGombeCreditApplyDetailsWalletListAction()
        //获取评分配置
        loadGombeCreditStatusDetailsScoreAction()
    }

    /**
     * 放款中
     */
    private fun showGomeCreditApplyDisbursingView(){
        _binding?.imageStatusIcon?.setImageResource(R.mipmap.gombe_credit_image_status_disbursing_icon)

        _binding?.textStatusTips?.text = getString(R.string.vitaf_status_disbursing_1)
        _binding?.textStatusTips?.setTextColor(getColor(R.color.gombe_credit_FF191919))
        _binding?.textStatusTips2?.text = getString(R.string.vitaf_status_disbursing_2)
        _binding?.textStatus?.text = getString(R.string.vitaf_status_disbursing)
        _binding?.textStatus?.setTextColor(getColor(R.color.gombe_credit_FFF7A01E))
        _binding?.btnRefreshStatus?.visibility = View.GONE
        _binding?.textStatusTips3?.text = getString(R.string.vitaf_status_disbursing_3)
        _binding?.textStatusTips3?.visibility = View.VISIBLE
        _binding?.walletListView?.visibility = View.VISIBLE
        _binding?.btnFeedback?.visibility = View.GONE
        _binding?.btnDeleteData?.visibility = View.GONE

        _binding?.btnWalletAdd?.visibility = View.GONE
        //法语区才显示添加收款账户按钮
        if (VitafConfigs.isGombeCreditFrench()){
            _binding?.btnWalletAdd?.visibility = View.VISIBLE
        }
        //加载收款账户列表
        loaGombeCreditApplyDetailsWalletListAction()
        //获取评分配置
        loadGombeCreditStatusDetailsScoreAction()
    }

    /**
     * 已拒绝
     */
    private fun showGomeCreditApplyRejectedView(){
        _binding?.imageStatusIcon?.setImageResource(R.mipmap.gombe_credit_image_status_rejected_icon)

        _binding?.textStatusTips?.text = getString(R.string.vitaf_status_rejected_1)
        _binding?.textStatusTips?.setTextColor(getColor(R.color.gombe_credit_FFF95D50))
        _binding?.textStatusTips2?.text = getString(R.string.vitaf_status_rejected_2,VitafProcessHp.takeGombeCreditApplyAgainDate())
        _binding?.textStatus?.text = getString(R.string.vitaf_status_rejected)
        _binding?.textStatus?.setTextColor(getColor(R.color.gombe_credit_FFFF4D3E))
        _binding?.btnRefreshStatus?.visibility = View.GONE
        _binding?.textStatusTips3?.visibility = View.GONE
        _binding?.walletListView?.visibility = View.GONE
        _binding?.btnFeedback?.visibility = View.VISIBLE
        _binding?.btnDeleteData?.visibility = View.GONE

        _binding?.btnWalletAdd?.visibility = View.GONE

        submitGombeCreditUserClearDataAction(true)
    }

    fun showGombeCreditApplyDetailsWalletList(walletList: ArrayList<JSONObject>) {
        walletAdapter?.data = walletList

        //法语地区 && 绑卡账户只有一个，需要提示
        if (VitafConfigs.isGombeCreditFrench() && walletList.size == 1){
            showGombeCreditApplyDetailsWalletOnlyOneDialog()
        }
    }

    /**
     * 法语地区 绑卡账户只有一个提示
     */
    private fun showGombeCreditApplyDetailsWalletOnlyOneDialog(){
        if (walletOnlyOneDialog == null){
            walletOnlyOneDialog = VitafStatusDetailsWalletOnlyOneDlog(requireContext(),pageName,object : VitafStatusDetailsWalletOnlyOneDlog.IDialogCallback{
                override fun onClick(view: View?) {
                    when(view?.id){
                        R.id.btnWalletAdd -> {//继续添加
                            _binding?.btnWalletAdd?.callOnClick()
                        }
                    }
                }
            })
            walletOnlyOneDialog?.setCancelable(true)
            walletOnlyOneDialog?.setCanceledOnTouchOutside(true)
        }
        walletOnlyOneDialog?.let { dialog ->
            if (getAct().isFinishing || getAct().isDestroyed || dialog.isShowing){
                return
            }
            dialog.show()
        }
    }

    /**
     * 清空用户数据dialog
     */
    private fun showGombeCreditClearDataDialog(){
        val clearDialog = VitafUserDataDeleteDlog(requireContext(),pageName,object : VitafUserDataDeleteDlog.IDialogCallback{
            override fun onUserDataClearConfirmClick() {
                //删除用户数据
                submitGombeCreditUserClearDataAction(false)
            }
        })
        clearDialog.setCancelable(true)
        clearDialog.setCanceledOnTouchOutside(true)
        clearDialog.show()
        clearDialog.showGombeCreditUserDataDeleteInfo(VitafConfigsHp.takeGombeCreditDeletePersonalDataDesc(),deleteDataAfterDate)
    }

    /**
     * 添加绑卡dialog
     */
    private fun showGombeCreditWalletAddDialog(){
        addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_CLICK.USER_WALLET_ADD,pageName)
        val bindCardDialog = VitafWalletAddDlog(requireContext(),pageName,object : VitafWalletAddDlog.IDialogCallback{
            override fun onClick(view: View?) {
            }
            override fun onSubmitParams(typeObj: JSONObject, phoneNumber: String) {
                onGombeCreditSubmitWalletAddAction(phoneNumber,typeObj.optString("value"))
            }
        })
        bindCardDialog.setCancelable(true)
        bindCardDialog.setCanceledOnTouchOutside(false)
        bindCardDialog.show()
    }

    /**
     * 提示绑定另一个账号
     */
    fun showGombeCreditWalletOtherDialog(otherInfo: JSONObject) {
        val bindOtherDialog = VitafWalletBindOtherDlog(requireContext(),pageName,object : VitafWalletBindOtherDlog.IDialogCallback{
            override fun onClick(view: View?) {
                if (view?.id == R.id.buttonWalletOtherConfirm){//添加
                    onGombeCreditSubmitWalletAddAction(otherInfo.optString("walletMobile"),otherInfo.optString("value"), "YES")
                }
            }
        })
        bindOtherDialog.setCancelable(true)
        bindOtherDialog.setCanceledOnTouchOutside(false)
        bindOtherDialog.show()
        bindOtherDialog.showGombeCreditWalletInfo(otherInfo)
    }

    /**
     * 删除提示
     */
    private fun showGombeCreditWalletDeleteDialog(item: JSONObject){
        item.put("walletLogo",item.optString("logo"))
        item.put("walletDesc",item.optString("name"))
        item.put("walletMobile",item.optString("account"))
        addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_CLICK.USER_WALLET_DELETE,item.optString("cardId"))
        val deleteDialog = VitafWalletDeleteDlog(requireContext(),pageName, object : VitafWalletDeleteDlog.IDialogCallback{
            override fun onClick(view: View?) {
                if (view?.id == R.id.walletAccountDeleteConfirm){
                    onGombeCreditDeleteWalletAction(item.optString("cardId"))
                }
            }
        })
        deleteDialog.setCancelable(true)
        deleteDialog.setCanceledOnTouchOutside(true)
        deleteDialog.show()
        deleteDialog.showGombeCreditWalletInfo(item)
    }

    /**
     * 获取贷款信息
     */
    private fun loadGombeCreditApplyDetailsAction(){
        val params = JSONObject().addCommonParams().apply {
            put("path", GombeCreditApiPath.GOMBECREDIT_PATH.GOMBECREDIT_API_APPLY_DETAILS_PATH)
        }
        val httpUrl = GombeCreditApiUrl.takeRequestUrl()
        doPostAction(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val obj = data.optJSONObject("obj")
                if (obj != null){
                    showGombeCreditApplyDetails(obj)
                }
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
                hideVitafLoading()
            }
        })
    }

    /**
     * 获取账户列表
     */
    private fun loaGombeCreditApplyDetailsWalletListAction(){
        val httpUrl = GombeCreditApiUrl.takeRequestUrl()
        val params = JSONObject().addCommonParams().apply {
            put("path", GombeCreditApiPath.GOMBECREDIT_PATH.GOMBECREDIT_API_ACCOUNT_LIST_PATH)
        }
        doPostAction(httpUrl, params, object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val array = data.optJSONArray("obj")
                val walletList = arrayListOf<JSONObject>()

                if (array != null && array.length() > 0) {
                    for (i in 0..<array.length()) {
                        val item = array.optJSONObject(i)
                        item.put("isShowDelete", VitafConfigs.isGombeCreditFrench())
                        walletList.add(item)
                    }
                }
                showGombeCreditApplyDetailsWalletList(walletList)
            }
            override fun onRequestError(error: JSONObject) {
            }
            override fun onRequestFinish() {
                hideVitafLoading()
            }
        })
    }

    /**
     * 清除用户数据 或 获取是否显示删除数据按钮
     */
    private fun submitGombeCreditUserClearDataAction(isShowDeleteButton: Boolean){
        showVitafLoading()
        val httpUrl = GombeCreditApiUrl.takeRequestUrl()
        val params = JSONObject().addCommonParams().apply {
            put("path", GombeCreditApiPath.GOMBECREDIT_PATH.GOMBECREDIT_API_USER_DATA_CLEAR_PATH)
        }
        if (isShowDeleteButton){
            params.put("type","GET")
        } else {
            params.put("type","DROP")
        }
        doPostAction(httpUrl, params, object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                if (isShowDeleteButton){
                    val obj = data.optJSONObject("obj")
                    obj?.let {
                        it.put("showDropButton","YES")
                        if (it.has("showDropButton") && it.optString("showDropButton") == "YES"){
                            _binding?.btnDeleteData?.visibility = View.VISIBLE
                            deleteDataAfterDate = it.optString("againDate")
                        } else {
                            _binding?.btnDeleteData?.visibility = View.GONE
                        }
                    }
                } else {
                    hideVitafLoading()
                    //退出登录，需要移除用户保存的信息
                    VitafSharedHp.onGombeCreditLoginOut()
                    onIntent(VitafUserLoginAct::class.java)
                }
            }
            override fun onRequestError(error: JSONObject) {
                showVitafToast(error.optString("errorMsg"))
            }
            override fun onRequestFinish() {
                hideVitafLoading()
            }
        })
    }

    /**
     * 添加绑卡
     */
    private fun onGombeCreditSubmitWalletAddAction(mobile: String, walletChannel: String, bindFlag:String = "NO"){
        showVitafLoading()
        val httpUrl = GombeCreditApiUrl.takeRequestUrl()
        val params = JSONObject().addCommonParams().apply {
            put("path", GombeCreditApiPath.GOMBECREDIT_PATH.GOMBECREDIT_API_ACCOUNT_ADD_PATH)
            put("walletMobile", mobile)
            put("walletMobileConfirm", mobile)
            put("walletChannel", walletChannel)
            put("addBindFlag", bindFlag)
        }

        doPostAction(httpUrl, params, object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                //刷新列表
                loaGombeCreditApplyDetailsWalletListAction()
                when(data.optInt("code")) {
                    0 -> {//成功
                        val obj = data.optJSONObject("obj") ?: JSONObject()
                        // "YES/NO 是否需要提示用户这个号码可以绑另一个渠道的钱包"
                        val addBindFlag = obj.optString("addBindFlag")
                        if (addBindFlag == "YES") {
                            //需要提示绑定另一个渠道账户
                            var otherAccountInfo: JSONObject? = null

                            //用于从APP配置中获取（walletChannels）对应的信息
                            val channel = obj.optString("channel")
                            if (channel.isNotBlank()) {
                                val customize = VitafConfigsHp.takeGombeCreditConfigData()
                                if (customize != null) {
                                    val walletChannels = customize.optJSONArray("walletChannels")
                                    if (walletChannels != null && walletChannels.length() > 0) {
                                        for (i in 0..<walletChannels.length()) {
                                            val item = walletChannels.optJSONObject(i)
                                            if (channel == item.optString("value")) {
                                                otherAccountInfo = item
                                                break
                                            }
                                        }
                                    }

                                    // 只有非空的情况下才处理
                                    if (otherAccountInfo != null) {
                                        otherAccountInfo.put("walletMobile", mobile)
                                        //提示绑定另一个渠道账户
                                        showGombeCreditWalletOtherDialog(otherAccountInfo)
                                        return
                                    }
                                }
                            }
                        } else {
                            hideVitafLoading()
                        }
                    }
                    else -> {
                        val msg = data.optString("msg")
                        showVitafToast(msg)
                    }
                }
            }
            override fun onRequestError(error: JSONObject) {
            }
            override fun onRequestFinish() {
                hideVitafLoading()
            }
        })
    }

    /**
     * 删除账户
     */
    fun onGombeCreditDeleteWalletAction(ids: String) {
        showVitafLoading()
        val httpUrl = GombeCreditApiUrl.takeRequestUrl()
        val params = JSONObject().addCommonParams().apply {
            put("path", GombeCreditApiPath.GOMBECREDIT_PATH.GOMBECREDIT_API_ACCOUNT_DELETE_PATH)
            put("ids", ids)
        }
        doPostAction(httpUrl, params, object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                //刷新列表
                loaGombeCreditApplyDetailsWalletListAction()
            }
            override fun onRequestError(error: JSONObject) {
            }
            override fun onRequestFinish() {
                hideVitafLoading()
            }
        })
    }

    /**
     * 只有审核中或放款中需要调此接口
     * 获取评分配置
     */
    private fun loadGombeCreditStatusDetailsScoreAction() {
        val httpUrl = GombeCreditApiUrl.takeRequestUrl()
        val params = JSONObject().addCommonParams().apply {
            put("path", GombeCreditApiPath.GOMBECREDIT_PATH.GOMBECREDIT_API_STAR_COMMENT_PATH)
        }
        doPostAction(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val obj = data.optJSONObject("obj")
                if (obj != null) {
                    VitafScoreDialogHp.showStarDialog(requireContext(),obj,true)
                }
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
            }
        })
    }


    override fun onVitafPublishEvent(event: VitafEventData) {
        super.onVitafPublishEvent(event)
        when(event.eventType){
            VitafEventData.TYPE.GOMBECREDIT_PROCESS_REFRESHED,
            VitafEventData.TYPE.GOMBECREDIT_DATA_REFRESH-> {//流程刷新完成
                //审核中 || 放款中 || 已拒绝
                val isReviewing = VitafProcessHp.isGombeCreditReviewing()
                val isDisbursing = VitafProcessHp.isGombeCreditDisbursing()
                val isRejected = VitafProcessHp.isGombeCreditRejected()
                if (isReviewing or isDisbursing or isRejected){
                    loadGombeCreditApplyDetailsAction()
                }
            }
            else -> {
            }
        }
    }

    override fun hideVitafLoading() {
        super.hideVitafLoading()
        _binding?.statusPageRefreshLayout?.isRefreshing = false
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    override fun onDestroy() {
        super.onDestroy()
        //审核中
        val isReviewing = VitafProcessHp.isGombeCreditReviewing()
        if (isReviewing){
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_PAGE.LOAN_REVIEWING_END)
            return
        }
        //放款中
        val isDisbursing = VitafProcessHp.isGombeCreditDisbursing()
        if (isDisbursing){
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_PAGE.LOAN_DISBURSING_END)
            return
        }
        //已拒绝
        val isRejected = VitafProcessHp.isGombeCreditRejected()
        if (isRejected){
            addEventPointRequestAction(VitafEventPointType.GOMBECREDIT_TRACK_PAGE.LOAN_REJECTED_END)
            return
        }
    }
}